class_name Barrel
extends StaticBody2D


@onready var damage_receiver: DamageReceiver = $DamageReceiver
@onready var sprite: Sprite2D = $Sprite2D
@onready var stateMachine: NodeStateMachine = $StateMachine


# 内容物类型，在被摧毁时掉落
@export var content_type: Collectible.Type
# 受到攻击产生击退效果的强度
@export var knockback_intensity: float
# 销毁前消失的速度
@export var dissipate_speed: float = 3.0


const STATE_IDLE := "idle"
const STATE_DESTROYED := "destroyed"


var __damage_emit_direction: Vector2


func _ready():
	damage_receiver.damage_received.connect(on_receive_damage)



func take_damage_emit_direction() -> Vector2:
	return __damage_emit_direction


func on_receive_damage(_damage: int, emit_direction: Vector2, _hit_type: DamageReceiver.HitType):
	__damage_emit_direction = emit_direction
	stateMachine.transition_to(STATE_DESTROYED)
